var t = getApp()
Page({
  data: {
    list:[],
    navHeight:t.globalData.navHeight,
    title:'门店管理',
  },
  onLoad: function (options) {

  },
  onShow(e){
    this.get_list()
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.get_list()
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  get_list(e){
    var that = this
    t.request('/store/sitelist',{},function(e){
      console.log(e);
      if (e.code==200) {
        var list = e.result
        that.setData({
          list:list
        })
      }
    })
  },
  open_door(e){
    var that = this
    wx.showLoading({
      title: '开门中…',
      mask:true
    })
    t.request('/store/openthegate',{site_id:e.currentTarget.dataset.id},function(e){
      console.log(e);
      if (e.code==200) {
        wx.hideLoading({
          success: (res) => {wx.showToast({
            title: e.msg,
          })},
        })
      }else{
        wx.hideLoading({
          success: (res) => {wx.showToast({
            title: e.msg,
          })},
        })
      }
    })
  }
})